package wht.jly.forum.domain;

/**
 * 发帖分类
 *
 * @author lanyangji
 * @date 2019/2/13 14:19
 */
public enum PostingType {

    QUESTION("提问帖", 1),
    TECHNOLOGY_SHARING("技术分享帖", 2),
    OTHER("其他", 3);

    /**
     * 名称
     */
    private String name;
    /**
     * 索引
     */
    private Integer index;

    /**
     * 构造器
     *
     * @param name
     * @param index
     */
    private PostingType(String name, Integer index) {
        this.name = name;
        this.index = index;
    }

    /**
     * 通过索引获取枚举对象
     *
     * @param index 索引
     * @return
     */
    public static PostingType getFromIndex(Integer index) {
        PostingType[] values = PostingType.values();
        for (PostingType value : values) {
            if (value.getIndex().equals(index)) {
                return value;
            }
        }

        return null;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getIndex() {
        return index;
    }

    public void setIndex(Integer index) {
        this.index = index;
    }

    @Override
    public String toString() {
        return "PostingType{" +
                "name='" + name + '\'' +
                ", index=" + index +
                '}';
    }
}
